import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store = new Vuex.Store({
  state:{
    count:101,
    list:['1','2','3','4','5','6','7','8','9','10']
  },
  mutations:{
    addCount(state){
     state.count++
    },
    changeCount(state,value){
      state.count = value
    },
    addCounts(state,num){
      state.count += num
    }

  },
  actions:{
    // 异步只能通过actions来执行
    asyncCount(content){
      setTimeout(()=>{
        content.commit('addCount')
      },1000)

    },
    asyncCounts(content,num){
      setTimeout(()=>{
        content.commit('addCounts',num)
      },1000)
    }
  },
  getters:{
    arr(state){
    return state.list.filter(item=>item>5)
    }
  }
})

export default store
